package com.hzlj.position.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.fz.common.base.core.RequestUtil;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.Collections;

@EnableTransactionManagement
@Configuration
@MapperScan(
        basePackages = {
                com.hzlj.sqjz.config.common.constant.Constant.MAPPER_PATH,
                com.hzlj.sqjz.system.common.constant.Constant.MAPPER_PATH,
                com.hzlj.sqjz.jz.common.constant.Constant.MAPPER_PATH,
                com.hzlj.sqjz.login.common.constant.Constant.MAPPER_PATH,
                com.hzlj.sqjz.lc.common.constant.Constant.MAPPER_PATH,
                com.hzlj.sqjz.writ.common.constant.Constant.MAPPER_PATH,
                com.hzlj.sqjz.report.common.constant.Constant.MAPPER_PATH,
                com.hzlj.position.config.common.constant.Constant.MAPPER_PATH,
                com.hzlj.position.locate.common.constant.Constant.MAPPER_PATH,
                com.hzlj.position.stat.common.constant.Constant.MAPPER_PATH,
                com.hzlj.position.job.common.constant.Constant.MAPPER_PATH,
        }
)
public class MybatisPlusConfig {

    /**
     * 分页插件 3.5.X
     */
    @Bean
    public PaginationInnerInterceptor paginationInnerInterceptor() {
        PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor();
        // 设置最大单页限制数量，默认 500 条，-1 不受限制
        paginationInterceptor.setMaxLimit(100L);
        // 开启 count 的 join 优化,只针对部分 left join
        paginationInterceptor.setOptimizeJoin(true);
        paginationInterceptor.setDbType(RequestUtil.getDbType());
        return paginationInterceptor;
    }

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        mybatisPlusInterceptor.setInterceptors(Collections.singletonList(paginationInnerInterceptor()));
        return mybatisPlusInterceptor;
    }
}
